package com.carey.blog.util.comparator;

import java.util.Comparator;
import java.util.Date;

import org.json.JSONObject;

import com.carey.blog.model.Article;


/**
 * Article comparator by update date.
 * 
 */
public final class ArticleUpdateDateComparator implements
		Comparator<JSONObject> {

	/**
	 * Package default constructor.
	 */
	ArticleUpdateDateComparator() {
	}

	@Override
	public int compare(final JSONObject article1, final JSONObject article2) {
		try {
			final Date date1 = (Date) article1.get(Article.ARTICLE_UPDATE_DATE);
			final Date date2 = (Date) article2.get(Article.ARTICLE_UPDATE_DATE);

			return date2.compareTo(date1);
		} catch (final Exception e) {
			throw new RuntimeException(e);
		}
	}
}
